
package fr.ece.ing4.si.monteCarlo;

public class MonteCarloThread  {

    // Function
    public double monteCarloStandardOption1(String callPutFlag, double s, double x, double t, double r,
                                           double b, double v, double nSteps, double nSimulations) {
        double dt, st, sum = 0.0, drift, vsqrdt;
        int i, j, z;
        z=0;
        
        dt = t / nSteps;
        drift = (b - Math.pow(v, 2) / 2) * dt;
        vsqrdt = v * Math.sqrt(dt);
        if (callPutFlag.equals("call"))
            z = 1;
        else if (callPutFlag.equals("put"))
            z = -1;
        
        for (i = 0; i < nSimulations; i++) {
        	java.util.Random random = new java.util.Random();
            st = s;
            for (j = 0; j < nSteps; j++) {
                st = st * Math.exp(drift + vsqrdt * random.nextGaussian());
            }
            sum += Math.max(z * (st - x), 0);
        }
        System.out.println("result single " +Math.exp(-r * t) * (sum / nSimulations));
        return Math.exp(-r * t) * (sum / nSimulations);
    }

}